<script src="http://protozoa.googlecode.com/svn/trunk/js/functions.js"></script>
<script src="http://protozoa.googlecode.com/svn/trunk/js/dom.js"></script>
<script src="http://protozoa.googlecode.com/svn/trunk/js/dom.event.js"></script>
<script src="http://protozoa.googlecode.com/svn/trunk/js/utils.js"></script>

<!--
<script src="/js/functions.js"></script>
<script src="/js/dom.js"></script>
<script src="/js/dom.event.js"></script>
<script src="/js/utils.js"></script>
<!---->

<style>body {font-size:11px} pre {font:11px mono;border-bottom:1px solid #ddd; padding-bottom:0.3em; margin:0.3em;}</style>

<script src='lex3.js'></script>
<script>


var text = load_file('lex3.js');
//text += text + text;
//var text_array = Array.prototype.slice.apply(text);

var f1 = function() {
	var count = 0;
	//var pat1 = 'function';
	//var pat2 = 'function';
	//var pl = Mapat.length;
	for (var i = 0, max = text.length ; i < max; ) {
		     if (false) 1
		else if (text.substr(i, 40)  == 'asdfjsdkfjsdkfjskdjfskdjfhsjkdfhkwjerhws') { ++count; i+=40}
		else if (text.substr(i, 20)  == 'last_accepting_state') { ++count; i+=20 }
		else if (text.substr(i, 18)  == 'last_accepting_pos') { ++count; i += 18 }
		else if (text.substr(i, 8)  == 'function')    { ++count; i += 8 }
		else if (text.substr(i, 6)  == 'yytext')      { ++count; i += 6 }
		else if (text.substr(i, 6)  == 'result')      { ++count; i += 6 }
		else if (text.substr(i, 5)  == 'trace')       { ++count; i += 5 }
		else if (text.substr(i, 5)  == 'state')       { ++count; i += 5 }
		else if (text.substr(i, 5)  == 'while')       { ++count; i += 5 }
		else if (text.substr(i, 5)  == 'assoc')       { ++count; i += 5 }
		else if (text.substr(i, 5)  == 'break')       { ++count; i += 5 }
		else if (text.substr(i, 3)  == 'var')         { ++count; i += 3 }
		else if (text.substr(i, 3)  == 'buf')         { ++count; i += 3 }
		else if (text.substr(i, 3)  == 'for')         { ++count; i += 3 }
		else ++i;
	}
	return count;
};

var count = 0;	


var l = {};
lex_merge(l, lex_re(parse_re('asdfjsdkfjsdkfjskdjfskdjfhsjkdfhkwjerhws'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('last_accepting_state'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('last_accepting_pos'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('function'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('yytext'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('result'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('trace'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('state'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('while'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('assoc'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('break'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('var'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('buf'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('for'), function(){ ++count }));




//lex_merge(l, lex_re(parse_re('asdfjkjkjkjkjretjfoeijccimwieorumwerwerieriweur'), function(){ ++count }));
//lex_merge(l, lex_re(parse_re('asd'), function(){ ++count }));



//lex_merge(l, lex_re(parse_re('result'), function(){ ++count }));
//lex_merge(l, lex_re(/./, function(){ trace('[.:' + yytext+']') }));
lex_merge(l, lex_re(/./));



/*
var l = {};
lex_merge(l, lex_re(parse_re('abc'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('ab'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('bd'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('b'), function(){ ++count }));
lex_merge(l, lex_re(/./));
*/

/*
var l = {};
lex_merge(l, lex_re(parse_re('aaaaa'), function(){ ++count }));
lex_merge(l, lex_re(parse_re('aa'), function(){ ++count }));
lex_merge(l, lex_re(/./));
*/

trace(dump(l));

//trace(lex_gen(l));





var f2 = function() {
	count = 0;
	lex_run(l, text);
	//lex_run(l, 'last');
	return count;
};


//alert(Array.prototype.slice.apply(x));

//alert(f2());




/*
var t0 = +new Date;
var result = f1();
var time = (+new Date) - t0;
alert('result: ' + result + '\ntime: ' + time);
/**/

/*
var t0 = +new Date;
var result = f2();
var time = (+new Date) - t0;
alert('result: ' + result + '\ntime: ' + time);
/**/


var re = /asdfjsdkfjsdkfjskdjfskdjfhsjkdfhkwjerhws|last_accepting_state|last_accepting_pos|function|yytext|result|trace|state|while|assoc|break|var|buf|for/g;
var f3 = function() {
	return text.match(re).length;
};

var f4 = function() {
	count = 0;
	text.replace(re, function($0) {
		switch ($0) {
			case 'asdfjsdkfjsdkfjskdjfskdjfhsjkdfhkwjerhws': ++count; break;
			case 'last_accepting_state': ++count; break;
			case 'last_accepting_pos': ++count; break;
			case 'function': ++count; break;
			case 'yytext': ++count; break;
			case 'result': ++count; break;
			case 'trace': ++count; break;
			case 'state': ++count; break;
			case 'while': ++count; break;
			case 'assoc': ++count; break;
			case 'break': ++count; break;
			case 'var': ++count; break;
			case 'buf': ++count; break;
			case 'for': ++count; break;
		}
		//return '';
		//return $0;
	});
	return count;
	
	//return text.match(re).length;
};



var actions = {
	'asdfjsdkfjsdkfjskdjfskdjfhsjkdfhkwjerhws': function() { ++count; },
	'last_accepting_state': function() { ++count; },
	'last_accepting_pos': function() { ++count; },
	'function': function() { ++count; },
	'yytext': function() { ++count; },
	'result': function() { ++count; },
	'trace': function() { ++count; },
	'state': function() { ++count; },
	'while': function() { ++count; },
	'assoc': function() { ++count; },
	'break': function() { ++count; },
	'var': function() { ++count; },
	'buf': function() { ++count; },
	'for': function() { ++count; }
};

var f5 = function() {
	count = 0;
	text.replace(re, function($0) {
		actions[$0]();
	});
	return count;
	
	//return text.match(re).length;
};



var f6 = function() {
	var out = [];
	for (var i = 0, max = text.length; i < max; ++i)
		switch (text[i]) {
			default: 1;
		}
};



var gen = lex_gen(l);
trace(''+gen);

var f7 = function() {
	count = 0;
	gen(text);
	return count;
};


var out = [];

var t0 = +new Date;
var result = f1();
var time = (+new Date) - t0;
out[out.length] = 'result f1: ' + result + '\ntime: ' + time;
/**/
var t0 = +new Date;
var result = f2();
var time = (+new Date) - t0;
out[out.length] = 'result f2: ' + result + '\ntime: ' + time;

var t0 = +new Date;
var result = f3();
var time = (+new Date) - t0;
out[out.length] = 'result f3: ' + result + '\ntime: ' + time;

var t0 = +new Date;
var result = f4();
var time = (+new Date) - t0;
out[out.length] = 'result f3: ' + result + '\ntime: ' + time;

var t0 = +new Date;
var result = f5();
var time = (+new Date) - t0;
out[out.length] = 'result f5: ' + result + '\ntime: ' + time;

var t0 = +new Date;
var result = f6();
var time = (+new Date) - t0;
out[out.length] = 'result f6: ' + result + '\ntime: ' + time;

var t0 = +new Date;
var result = f7();
var time = (+new Date) - t0;
out[out.length] = 'result f7: ' + result + '\ntime: ' + time;

alert(out.join('\n'));

//run_time_test(f2);



</script>




















